The DualListSelector is a TransformationBean™ that generates the appropriate HTML 4.0 and JavaScript for creating a list-to list selector. A DualListSelector enables you to move single or multiple items between two list boxes and submit items that are selected in the target list box.
Here are the steps for creating a simple DualListSelector:
This sample shows how to create and render a JSP DualListSelector. The Full Code tab in this sample contains the complete code for all of the customizations below.
This example contains the following customizations:
A default DualListSelector looks like the following:
You might want to change properties of the components in the DualListSelector. You might want to change the text of the source and target labels, change the text of the submit button, add tooltips to the buttons, set an initial selected item in the source list, or add onClick methods to the components in the DualListSelector.
To change the properties described below, first follow these steps:
<%@page import="com.sas.servlet.tbeans.html.Button"%> <%@page import="com.sas.servlet.tbeans.html.Label"%> <%@page import="com.sas.servlet.tbeans.form.html.ListBox"%> <%@page import="com.sas.servlet.tbeans.dualselector.html.DualListSelector"%>
<sas:DualListSelector id="dualListSelector1" model="listmodel" render="false" />
<% Add your code to change the properties here %>
<sas:DualListSelector ref="dualListSelector1" render="true"/>
After you have completed the above steps, you are ready to make the following customizations:
To get a component in the DualListSelector, you would call getComponent, passing in the name of the component you'd like to get. For example:
Button rightButton = (Button)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_RIGHT_BUTTON);
To add a tool tip to a button, you would call setTitle on that button, passing in the text of the tool tip. For example:
rightButton.setTitle("Move To Target");
To display the move all right or move all left button, you would call setVisible(true) on that button. For example:
Button rightAllButton = (Button)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_RIGHT_ALL_BUTTON); rightAllButton.setVisible(true);
To change the image or text displayed on a button, you would call setImage or setTitle on that button, passing in the image location or text for that button. For example:
Button submitButton = (Button)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_SUBMIT_BUTTON); submitButton.setLabel("OK");
To change the text of the source or target label, you would call setText on that label, passing in the new text. For example:
Label sourceLabel = (Label)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_SOURCE_LABEL); sourceLabel.setText("Available");
To set the selected item in the source list box, you would call setSelectedItem on the source component, passing in the selected item. For example:
ListBox sourceListBox = (ListBox)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_SOURCE); sourceListBox.setSelectedItem("Item 2");
To set an action to occur when you click on the target list box, call setOnClick on the target component, passing in the method or code you'd like to execute. For example:
ListBox targetListBox = (ListBox)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_TARGET); targetListBox.setOnClick("alert('target listbox clicked')");
You can see some of these changes in the following screen capture:
To change the styles, you should perform these tasks:
<%@page import="com.sas.servlet.tbeans.StyleInfo"%> <%@page import="java.util.Map"%>
<style> .myContainer { border-style: dashed; border-width: medium;border-color: #F1EACB;} .mySourceListBox, .myTargetListBox{ width:200; color:#3872ac;} .mySourceLabel, .myTargetLabel{background-color="#3872ac";color:#F1EACB;font-family: Trebuchet MS, Helvetica, sans-serif;font-weight: bold;} </style>
<sas:DualListSelector id="dualListSelector1" model="listmodel" render="false" />
<% Map map = dualListSelector1.getStyleMap(); map.put(DualListSelector.DUALSELECTOR_CONTAINER, new StyleInfo("myContainer")); map.put(DualListSelector.DUALSELECTOR_SOURCE_LISTBOX, new StyleInfo("mySourceListBox")); map.put(DualListSelector.DUALSELECTOR_TARGET_LISTBOX, new StyleInfo("myTargetListBox")); map.put(DualListSelector.DUALSELECTOR_SOURCE_LABEL_AREA, new StyleInfo("mySourceLabel")); map.put(DualListSelector.DUALSELECTOR_TARGET_LABEL_AREA, new StyleInfo("myTargetLabel")); %>
<sas:DualListSelector ref="dualListSelector1" render="true"/>
You will get a DualListSelector that looks like:
You might want to change the visuals of the DualListSelector by creating your own template. The following customization shows you how to remove the target list move up/down buttons, move the submit button to the right side from the center, and add a component below the source list box.
To create your own template and apply it to the DualListSelector, follow these steps:
<table border="0" cellspacing="0" cellpadding="0" class="%DUALSELECTOR_CONTAINER">
<tr>
<td class="%DUALSELECTOR_SOURCE_LABEL_AREA">%DUALSELECTOR_SOURCE_LABEL</td>
<td> </td>
<td class="%DUALSELECTOR_TARGET_LABEL_AREA">%DUALSELECTOR_TARGET_LABEL</td>
</tr>
<tr>
<td>%DUALSELECTOR_SOURCE </td>
<td valign="center" align="center" nowrap="nowrap">
<table>
<tr>
<td>%DUALSELECTOR_RIGHT_BUTTON</td>
</tr>
<tr>
<td>%DUALSELECTOR_LEFT_BUTTON</td>
</tr>
<tr>
<td height="10px"></td>
</tr>
<tr>
<td>%DUALSELECTOR_RIGHT_ALL_BUTTON</td>
</tr>
<tr>
<td>%DUALSELECTOR_LEFT_ALL_BUTTON</td>
</tr>
</table>
</td>
<td>%DUALSELECTOR_TARGET</td>
</tr>
<tr><td>%DUALSELECTOR_TEXTENTRY</td></tr>
<tr>
<td colspan="3" align="right">%DUALSELECTOR_SUBMIT_BUTTON</td>
</tr>
</table>
|
<%@page import="com.sas.servlet.tbeans.form.html.TextEntry"%>
|
<sas:DualListSelector id="dualListSelector1" model="listmodel" render="false" />
|
<%
dualListSelector1.setTemplateFileName("DualListSelector_Custom.html");
TextEntry textentry = new TextEntry();
textentry.setName("search");
dualListSelector1.setComponent("DUALSELECTOR_TEXTENTRY", textentry);
%>
|
<sas:DualListSelector ref="dualListSelector1" render="true"/>
|
You will get a DualListSelector that looks like this:
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Tip: For help with building a Web application project and testing a Web application, see SAS Note 32218.
<%@ taglib uri="http://www.sas.com/taglib/sas" prefix="sas" %>
<%@ page pageEncoding="UTF-8"%>
<%@page import="javax.swing.DefaultListModel"%>
<html>
<head>
<link href="styles/sasComponents.css" rel="STYLESHEET" type="text/css">
</head>
<body>
<%
DefaultListModel listModel = new DefaultListModel();
listModel.addElement("Item 1");
listModel.addElement("Item 2");
listModel.addElement("Item 3");
listModel.addElement("Item 4");
listModel.addElement("Item 5");
listModel.addElement("Item 6");
session.setAttribute("listModel", listModel);
%>
<sas:DualListSelector id="dualListSelector1" model="listModel" render="true" />
</body>
</html>
|
<%@ taglib uri="http://www.sas.com/taglib/sas" prefix="sas" %>
<%@ page pageEncoding="UTF-8"%>
<%@page import="javax.swing.DefaultListModel"%>
<%@page import="com.sas.servlet.tbeans.html.Button"%>
<%@page import="com.sas.servlet.tbeans.html.Label"%>
<%@page import="com.sas.servlet.tbeans.form.html.ListBox"%>
<%@page import="com.sas.servlet.tbeans.dualselector.html.DualListSelector"%>
<html>
<head>
<link href="styles/sasComponents.css" rel="STYLESHEET" type="text/css">
</head>
<body>
<%
DefaultListModel listModel = new DefaultListModel();
listModel.addElement("Item 1");
listModel.addElement("Item 2");
listModel.addElement("Item 3");
listModel.addElement("Item 4");
listModel.addElement("Item 5");
listModel.addElement("Item 6");
session.setAttribute("listModel", listModel);
%>
<sas:DualListSelector id="dualListSelector1" model="listModel" render="false" />
<%
Button rightButton =
(Button)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_RIGHT_BUTTON);
Button leftButton =
(Button)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_LEFT_BUTTON);
Button rightAllButton =
(Button)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_RIGHT_ALL_BUTTON);
Button leftAllButton =
(Button)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_LEFT_ALL_BUTTON);
Button downButton =
(Button)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_DOWN_BUTTON);
Button upButton =
(Button)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_UP_BUTTON);
Button submitButton =
(Button)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_SUBMIT_BUTTON);
//Add tooltips for the buttons
rightButton.setTitle("Move To Target");
leftButton.setTitle("Move To Source");
rightAllButton.setTitle("Move All To Target");
leftAllButton.setTitle("Move All To Source");
downButton.setTitle("Move Down");
upButton.setTitle("Move Up");
//The default visible state is true.
//If visible is set to false, the components will not be written out
rightAllButton.setVisible(true);
leftAllButton.setVisible(true);
upButton.setImage("images/arrow-up-default.gif");
downButton.setImage("images/arrow-down-default.gif");
submitButton.setLabel("OK");
submitButton.setTitle("Submit Selections");
Label sourceLabel =
(Label)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_SOURCE_LABEL);
Label targetLabel =
(Label)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_TARGET_LABEL);
sourceLabel.setText("Available");
targetLabel.setText("Selected");
ListBox sourceListBox =
(ListBox)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_SOURCE);
ListBox targetListBox =
(ListBox)dualListSelector1.getComponent(DualListSelector.DUALSELECTOR_TARGET);
sourceListBox.setSelectedItem("Item 2");
targetListBox.setOnClick("alert('target listbox clicked')");
%>
<sas:DualListSelector ref="dualListSelector1" render="true"/>
</body>
</html>
|
<%@ taglib uri="http://www.sas.com/taglib/sas" prefix="sas" %>
<%@ page pageEncoding="UTF-8"%>
<%@page import="javax.swing.DefaultListModel"%>
<%@page import="com.sas.servlet.tbeans.dualselector.html.DualListSelector"%>
<%@page import="com.sas.servlet.tbeans.StyleInfo"%>
<%@page import="java.util.Map"%>
<html>
<head>
<style>
.myContainer { border-style: dashed; border-width: medium;border-color: #F1EACB;}
.mySourceListBox, .myTargetListBox{ width:200; color:#3872ac;}
.mySourceLabel, .myTargetLabel{background-color="#3872ac";color:#F1EACB;font-family:
Trebuchet MS, Helvetica, sans-serif;font-weight: bold;}
</style>
</head>
<body>
<%
DefaultListModel listModel = new DefaultListModel();
listModel.addElement("Item 1");
listModel.addElement("Item 2");
listModel.addElement("Item 3");
listModel.addElement("Item 4");
listModel.addElement("Item 5");
listModel.addElement("Item 6");
session.setAttribute("listModel", listModel);
%>
<sas:DualListSelector id="dualListSelector1" model="listModel" render="false" />
<%
Map map = dualListSelector1.getStyleMap();
map.put(DualListSelector.DUALSELECTOR_CONTAINER, new StyleInfo("myContainer"));
map.put(DualListSelector.DUALSELECTOR_SOURCE_LISTBOX, new StyleInfo("mySourceListBox"));
map.put(DualListSelector.DUALSELECTOR_TARGET_LISTBOX, new StyleInfo("myTargetListBox"));
map.put(DualListSelector.DUALSELECTOR_SOURCE_LABEL_AREA, new StyleInfo("mySourceLabel"));
map.put(DualListSelector.DUALSELECTOR_TARGET_LABEL_AREA, new StyleInfo("myTargetLabel"));
%>
<sas:DualListSelector ref="dualListSelector1" render="true"/>
</body>
</html>
|
To use this template, you must also add the DualListSelector_Custom.html template found below:
<%@ taglib uri="http://www.sas.com/taglib/sas" prefix="sas" %>
<%@ page pageEncoding="UTF-8"%>
<%@page import="javax.swing.DefaultListModel"%>
<%@page import="javax.swing.ListModel"%>
<%@page import="com.sas.servlet.tbeans.form.html.TextEntry"%>
<html>
<head>
<link href="styles/sasComponents.css" rel="STYLESHEET" type="text/css">
</head>
<body>
<%
ListModel listmodel = new DefaultListModel();
((DefaultListModel)listmodel).addElement("Item 1");
((DefaultListModel)listmodel).addElement("Item 2");
((DefaultListModel)listmodel).addElement("Item 3");
((DefaultListModel)listmodel).addElement("Item 4");
((DefaultListModel)listmodel).addElement("Item 5");
((DefaultListModel)listmodel).addElement("Item 6");
session.setAttribute("listmodel", listmodel);
%>
<sas:DualListSelector id="dualListSelector1" model="listmodel" render="false" />
<%
dualListSelector1.setTemplateFileName("DualListSelector_Custom.html");
TextEntry textentry = new TextEntry();
textentry.setName("search");
dualListSelector1.setComponent("DUALSELECTOR_TEXTENTRY", textentry);
%>
<sas:DualListSelector ref="dualListSelector1" render="true"/>
</body>
</html>
|
This file must be created under the templates directory in the Web application:
<table border="0" cellspacing="0" cellpadding="0" class="%DUALSELECTOR_CONTAINER">
<tr>
<td class="%DUALSELECTOR_SOURCE_LABEL_AREA">%DUALSELECTOR_SOURCE_LABEL</td>
<td> </td>
<td class="%DUALSELECTOR_TARGET_LABEL_AREA">%DUALSELECTOR_TARGET_LABEL</td>
</tr>
<tr>
<td>%DUALSELECTOR_SOURCE </td>
<td valign="center" align="center" nowrap="nowrap">
<table>
<tr>
<td>%DUALSELECTOR_RIGHT_BUTTON</td>
</tr>
<tr>
<td>%DUALSELECTOR_LEFT_BUTTON</td>
</tr>
<tr>
<td height="10px"></td>
</tr>
<tr>
<td>%DUALSELECTOR_RIGHT_ALL_BUTTON</td>
</tr>
<tr>
<td>%DUALSELECTOR_LEFT_ALL_BUTTON</td>
</tr>
</table>
</td>
<td>%DUALSELECTOR_TARGET</td>
</tr>
<tr><td>%DUALSELECTOR_TEXTENTRY</td></tr>
<tr>
<td colspan="3" align="right">%DUALSELECTOR_SUBMIT_BUTTON</td>
</tr>
</table>
|
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Date Modified: | 2008-08-07 15:33:21 |
Date Created: | 2006-02-09 15:59:16 |
Product Family | Product | Host | Product Release | SAS Release | ||
Starting | Ending | Starting | Ending | |||
SAS System | SAS AppDev Studio | Microsoft Windows Server 2003 Enterprise Edition | 3.2 | 9.1 TS1M3 SP4 | ||
Microsoft® Windows® for x64 | 3.2 | 9.1 TS1M3 SP4 | ||||
Microsoft Windows 2000 Server | 3.2 | 9.1 TS1M3 SP4 | ||||
Microsoft Windows 2000 Datacenter Server | 3.2 | 9.1 TS1M3 SP4 | ||||
Microsoft Windows NT Workstation | 3.2 | 9.1 TS1M3 SP4 | ||||
Microsoft Windows Server 2003 Datacenter Edition | 3.2 | 9.1 TS1M3 SP4 | ||||
Microsoft Windows 2000 Professional | 3.2 | 9.1 TS1M3 SP4 | ||||
Microsoft Windows 2000 Advanced Server | 3.2 | 9.1 TS1M3 SP4 | ||||
Microsoft Windows Server 2003 Standard Edition | 3.2 | 9.1 TS1M3 SP4 | ||||
Microsoft Windows XP Professional | 3.2 | 9.1 TS1M3 SP4 | ||||
Windows Vista | 3.2 | 9.1 TS1M3 SP4 |